import Vue from 'vue';
import Vuex from 'vuex';
import config from '../utils/config';
let { host, bzhost, helphost, bzImg } = config.api;
// let type = config.type;
let { K2Page, cbUrl } = config.url;
let userNum = sessionStorage.getItem('userNum');
// userNum = 'shij13';
// userNum = 'shij13' shij13;
// userNum = 'zhangyq12';
Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        host,
        bzhost,
        bzImg,
        helphost,
        K2Page,
        cbUrl,
        userNum,
        sessionId: sessionStorage.getItem('sessionId') || '',
        userInfo: sessionStorage.getItem('userInfo') ? JSON.parse(sessionStorage.getItem('userInfo')) : {},
        avatar: window.localStorage.getItem('avatar') || '',
        title: window.sessionStorage.getItem('pageTitle') || '个人中心',
        isLoading: false
    },
    mutations: {
        isLoading (state, info) {
            state.isLoading = info;
        },
        sessionId (state, info) {
            state.sessionId = info;
            sessionStorage.setItem('sessionId', info);
            Vue.prototype.sessionId = info;
        },
        setTitle (state, info) {
            state.title = info;
            sessionStorage.setItem('pageTitle', info);
        },
        userNum (state, info) {
            state.userNum = info;
            sessionStorage.setItem('userNum', info);
        },
        userInfo (state, info) {
            state.userInfo = info;
            sessionStorage.setItem('userInfo', JSON.stringify(info));
            console.log('保存用户信息到store');
        },
        avatar(state, info) {
            state.avatar = info;
            localStorage.setItem('avatar', info);
        }
    }
});
